package sicnu.cs.aps.common.jasypt;

import org.jasypt.encryption.pbe.StandardPBEStringEncryptor;

//<!-- 配置文件加密 -->
//<dependency>
//<groupId>com.github.ulisesbocchio</groupId>
//<artifactId>jasypt-spring-boot-starter</artifactId>
//<version>2.1.1</version>
//</dependency>

/**
 * @author chenhetao
 * @version 1.0
 * @className JasyptEncoderAndDecoder
 * @description 加密解密工具
 * @date 2022/5/25 15:01
 */
//@SpringBootTest
public class JasyptEncoderAndDecoder {
    public static void main(String[] args) {
        //盐值
        String saltValue = "TEST";
        //明文
        String plaintext = "sicnu";
        //密文
        String ciphertext = "";

        StandardPBEStringEncryptor standardPBEStringEncryptor = new StandardPBEStringEncryptor();
        standardPBEStringEncryptor.setPassword(saltValue);
        if ("".equals(ciphertext)){
            //加密明文
            System.out.println("明文【" + plaintext +"】");
            System.out.println("⬇加密后⬇");
            System.out.println(ciphertext = standardPBEStringEncryptor.encrypt(plaintext));
        }else {
            System.out.println("密文【" + ciphertext +"】");
            System.out.println("⬇解密后⬇");
            System.out.println(standardPBEStringEncryptor.decrypt(ciphertext));
        }
    }


}
